﻿
Imports Cls_Common
Imports VSModel
Imports System.Data
Partial Class FrontEnd_Control_Menu_TopMenu
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            BindMenu()
        End If
    End Sub
    Protected Sub BindMenu()
        Using Data As New VSEntities
            Dim p = (From q In Data.Categories Where q.ParentId = 0 Select q Order By q.Sort).Take(5).ToList
            With rptMenu
                .DataSource = p
                .DataBind()
            End With
        End Using
    End Sub


    Protected Sub rptMenu_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptMenu.ItemDataBound
        Dim row As VSModel.Category = CType(e.Item.DataItem, VSModel.Category)
        Dim hplTitle As HyperLink = e.Item.FindControl("hplTitle")
        Dim lblTitle As Label = e.Item.FindControl("lblTitle")
        lblTitle.Text = row.Title
        Dim imgCat As Image = e.Item.FindControl("imgCat")
        hplTitle.NavigateUrl = MainDomain & "san-pham/" & row.QueryString & "-" & row.CatId & ".html"

        'If Page.RouteData.Values("Id") = row.CatId Then
        '    hplTitle.CssClass = "active"
        'End If

        Dim rptMenuChild As Repeater = CType(e.Item.FindControl("rptMenuChild"), Repeater)

        imgCat.ImageUrl = MainDomain & "FrontEnd/images/" & (e.Item.ItemIndex + 1).ToString & ".jpg"

        Using Data As New VSEntities
            Dim p = (From q In Data.Categories Where q.ParentId = row.CatId).ToList
            If p.Count > 0 Then
                rptMenuChild.DataSource = p
                rptMenuChild.DataBind()
            End If
        End Using


    End Sub
    Protected Sub rptMenuChild_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs)
        Dim row As VSModel.Category = CType(e.Item.DataItem, VSModel.Category)
        Dim hplTitle As HyperLink = CType(e.Item.FindControl("hplTitle"), HyperLink)
        hplTitle.Text = row.Title
        hplTitle.NavigateUrl = MainDomain & "san-pham/" & row.QueryString & "-" & row.CatId & ".html"
        Dim rptMenuThird As Repeater = CType(e.Item.FindControl("rptMenuThird"), Repeater)

        Using Data As New VSEntities
            'Lay toan bo cap con cua Cate

            Dim p = (From q In Data.Categories Where q.ParentId = row.CatId).ToList
            rptMenuThird.DataSource = p
            rptMenuThird.DataBind()

        End Using
    End Sub
    Protected Sub rptMenuThird_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs)
        Dim row As VSModel.Category = CType(e.Item.DataItem, VSModel.Category)
        Dim hplTitle As HyperLink = CType(e.Item.FindControl("hplTitle"), HyperLink)
        hplTitle.Text = row.Title
        hplTitle.NavigateUrl = MainDomain & "san-pham/" & row.QueryString & "-" & row.CatId & ".html"

    End Sub

End Class
